package com.liyu.rabbit.consumer;

import cn.hutool.core.date.DateUtil;
import com.liyu.rabbit.factory.RabbitFactory;
import com.liyu.rabbit.producer.Producer;
import com.rabbitmq.client.Channel;

import java.util.Date;

/**
 * @author 李誉
 * @date 2022-07-02 23:36
 * @description
 */
public class Consumer {
    public static final String RK = "delayed.hello.rk";
    public static final String QUEUE = "delayed.hello";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitFactory.createNewChannel();
        channel.queueDeclare(QUEUE, true, false, true, null);
        channel.queueBind(QUEUE, Producer.DELAYED_EX, RK, null);
        String consume ="队列 -%s- 消费一条消息：%s, 时间：%s";
        channel.basicConsume(QUEUE, false, (consumerTag, message) -> {
            System.out.println(String.format(consume, QUEUE, new String(message.getBody()) , DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
        }, (consumerTag) -> {
            System.out.println("队列 -"+QUEUE  + "- 消费一条消息" + consumerTag + "失败：");
        });
    }
}
